﻿using Blader.ActionHandler;
using EnvDTE;
using EnvDTE80;

namespace Blader.Executor
{
    public class CommandExecutor
    {
        private DTE2 applicationObject;
        private AddIn addInInstance;

        public DTE2 ApplicationObject
        {
            get { return applicationObject; }
            set { applicationObject = value; }
        }

        public AddIn AddInInstance
        {
            get { return addInInstance; }
            set { addInInstance = value; }
        }

        public void Execute(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                HandlerContext handlerContext = new HandlerContext(applicationObject, addInInstance, commandName);

                AbstractActionHandler abstractActionHandler = ActionHandlerFactory.GetHandler(handlerContext);

                if (abstractActionHandler != null)
                {
                    handled = abstractActionHandler.Execute();
                }
            }
        }
    }
}
